﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace WebCrawlerTools.search
{
    public class SResult
    {
        private SLine titleList;
        private ArrayList dataList;

        public ArrayList Data
        {
            get
            {
                return dataList;
            }
            set
            {
                dataList = value;
            }
        }

        public SLine Title
        {
            get
            {
                return titleList;
            }
            set
            {
                titleList = value;
            }
        }

        /// <returns>現在の <see cref="T:System.Object"></see> を表す <see cref="T:System.String"></see>。</returns>
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            //sb.AppendLine(titleList.ToString());
            foreach (SLine l in dataList)
            {
                sb.AppendLine(l.ToString());
            }
            return sb.ToString();
        }
        public string DataToString()
        {
            StringBuilder sb = new StringBuilder();
            foreach (SLine l in dataList)
            {
                sb.AppendLine(l.ToString());
            }
            return sb.ToString();
        }

        public ArrayList GetValByKey(string key)
        {
            ArrayList retVal = new ArrayList();
            int index = -1;
            for (int i = 0; i < Title.Data.Count; i++)
            {
                String title =(String) Title.Data[i];
                if (title == key)
                {
                    index = i;
                }
            }
            if (index != -1)
            {
                foreach (SLine l in Data)
                {
                    retVal.Add(l.Data[index]);
                }
            }
            return retVal;
        }

        public SResult()
        {
            titleList = new SLine();
            dataList = new ArrayList();
        }

        internal void Add(SResult data)
        {
            foreach (SLine sl in data.Data)
            {
                this.Data.Add(sl);
            }
        }
    }
}
